package util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class DataUtil {

	private static Connection conn;
	private static String DATA="jdbc:sqlserver://THIENVD;databaseName=QUANLYDEANCONGTY";
	private static String USER_NAME ="sa";
	private static String PASSWORD = "123456";
	
	public static void connect() {
		try {
			Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
			conn = DriverManager.getConnection(DATA, USER_NAME, PASSWORD);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}

	public static Connection getConnection() {
		if (conn == null) {
			connect();
		}
		return conn;
	}

	public static ResultSet executeQuery(String sql) {
		ResultSet rs = null;
		try {
			connect();
			Statement st = conn.createStatement();
			rs = st.executeQuery(sql);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return rs;
	}
}
